package mapred.example;

import java.io.IOException;
import java.util.Iterator;

import mapred.AbstractReducer;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

public class DoubleSumReducer extends
		AbstractReducer<Writable, Writable, Writable, DoubleWritable> {

	@Override
	public void reduce(Writable key, Iterator<Writable> values,
			OutputCollector<Writable, DoubleWritable> output, Reporter reporter)
			throws IOException {
		double sum = 0;
		while (values.hasNext()) {
			sum += Double.parseDouble(values.next().toString());
		}
		output.collect(key, new DoubleWritable(sum));
	}

	@Override
	public void setUp() {
	}

}
